package com.cn.wanxi.servlet.manage.nav;

import com.cn.wanxi.model.NavModel;
import com.cn.wanxi.service.INavService;
import com.cn.wanxi.service.impl.NavServiceImpl;
import net.sf.json.JSONArray;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/navFindById")
public class NavFindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        req.setCharacterEncoding("UTF-8");//请求编码格式为utf-8
//        resp.setCharacterEncoding("UTF-8");//响应编码格式为utf-8
//        resp.setContentType("text/json;charset=utf-8");//解决传值乱码
        //        1.得到页面的值
        String idString = req.getParameter("id");
        Integer id = idString == null ? 0 : Integer.parseInt(idString);
//        2.封装页面对象
//        NavModel navModel = new NavModel();
////        navModel.setId(id);
//        3.调用服务层
        INavService iNavService = new NavServiceImpl();
        NavModel model = iNavService.findById(id);
//        4. 返回页面数据
        JSONArray jsonArray=JSONArray.fromObject(model);
        resp.getWriter().println(jsonArray);
    }
}
